<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../vue.js"></script>
    <script src="../vue-router.js"></script>
    <style>
        .router-link-exact-active,
        .router-link-active {
            font-size: 30px;
            color: red;
            font-weight: bold;
            display: inline-block;
            padding: 20px 30px;
        }
    </style>
</head>

<body>
    <div class="app">
        <h1>{{title}}</h1>
        <hr>
        <router-view></router-view>
        <router-link to="/Home">首页</router-link>
        <router-link to="/Content">详情页</router-link>
        <router-link to="/Find">发现页</router-link>
        <router-link to="/User">个人中心</router-link>
    </div>
    <template id="home">
        <div>
            <h1>home</h1>
            <div>{{cont}}</div>
        </div>
    </template>
    <template id="content">
        <div>
            <h1>content</h1>
            <div>{{cont}}</div>
        </div>
    </template>
    <template id="user">
        <div>
            <h1>user</h1>
            <div>{{cont}}</div>
        </div>
    </template>
    <template id="find">
        <div>
            <h1>find</h1>
            <div>{{cont}}</div>
        </div>
    </template>
    <script>
        //定义路由组件
        const Home = {
            template: '#home',
            data() {
                return {
                    cont: "首页"
                }
            },
        }
        const Content = {
            template: '#content',
            data() {
                return {
                    cont: "详情页"
                }
            },
        }
        const User = {
            template: '#user',
            data() {
                return {
                    cont: "个人中心"
                }
            },
        }
        const Find = {
            template: '#find',
            data() {
                return {
                    cont: "发现页"
                }
            },
        }

        //配置路由,每个路由都需要映射到一个组件上
        const routers = [{
            path: '/Home',
            component: Home
        }, {
            path: '/Content',
            component: Content
        }, {
            path: '/User',
            component: User
        }, {
            path: '/Find',
            component: Find
        }, ]

        //创建实例化路由
        const router = new VueRouter({
            routes: routers
        })
        const vm = new Vue({
            //挂载路由
            router,
            data: {
                title: "路由功能：根据不同的路径，匹配不同的组件"
            }
        }).$mount(".app")
    </script>
</body>

</html>